package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.SinaMapper;
import com.itheima.pojo.Article;
import com.itheima.service.SinaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SinaServiceImpl extends ServiceImpl<SinaMapper, Article> implements SinaService {

    @Autowired
    private SinaMapper mapper;

    @Override
    public List<Article> findBywords(String keywords) {
        //接收检查参数,非空判断
        if (keywords == null || keywords == "") {
            return null;
        }
        //数据处理
        keywords = "%" + keywords + "%";
        //原始方法一:
        /*//调用mapper方法
        List<Article> articles = mapper.selectByname(keywords);
        return articles;*/

        //方法2:Lambda:方法
        LambdaQueryWrapper<Article> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(Article::getTitle, keywords);
        List<Article> articles = mapper.selectList(wrapper);
        return articles;
    }
}
